package com.chen.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chen.springboot.domain.Team;
import com.chen.springboot.entity.Poster;
import com.chen.springboot.mapper.PosterMapper;
import com.chen.springboot.mapper.TeamMapper;
import com.chen.springboot.service.TeamService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author chenchao
 * @date 2022/6/18 16:22
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class TeamServiceImpl extends ServiceImpl<TeamMapper,Team> implements TeamService {

    @Resource
    private TeamMapper teamMapper;

    public IPage<Team> selectPage(Integer pageNum, Integer pageSize,
                                  String displayAbbr,
                                  String displayConference,
                                  String division,
                                  String city) {
//        创建Page1对象
        IPage<Team> page = new Page<Team>(pageSize, pageNum);
//QueryWrapper如果name不为空进行模糊查询
        QueryWrapper queryWrapper = new QueryWrapper();

        if(!"".equals(displayAbbr)){
            queryWrapper.like("displayAbbr",displayAbbr);
        }

        if(!"".equals(displayConference)){
            queryWrapper.like("displayConference",displayConference);
        }
        if(!"".equals(division)){
            queryWrapper.like("division",division);
        }
        if(!"".equals(city)){
            queryWrapper.like("city",city);
        }
        Page<Team> selectPage = teamMapper.selectPage(new Page<>(pageNum, pageSize), queryWrapper);
        return selectPage;

    }

}
